#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define loop(i,a,n) for(int i = a; i <= n; i++)
#define loopr(i,n,a) for(int i = n; i >= a; i--)
#define foor(i,n) for(int i = 0; i < n; i++)
#define fore(el,v) for(auto& el:v)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define fast ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
#define endl '\n'
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using vvi = vector<vector<int>>;
const int MOD = 1e9+7;
const int OO = 1e9+5;
const int N = 2e5+5;
vi adj[N];
int ans, par[N];
void dfs(int v, int d){
ans = max(ans, d);
for(auto u : adj[v]){
dfs(u, d+1);
}
}
void TC()
{
int n, p; cin >> n;
loop(i,1,n){
cin >> p;
par[i] = p;
if(p>0) adj[p].pb(i);
}
loop(i,1,n){
if(par[i] != -1)
continue;
dfs(i,1);
}
cout << ans;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#endif
fast
int t = 1;
// cin >> t;
while (t--)
{
TC();
cout << '\n';
}
return 0;
}
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |
Lexical Sorting Reloaded | 1514A - Perfectly Imperfect Array |
580A- Kefa and First Steps | 1472B- Fair Division |
996A - Hit the Lottery | MSNSADM1 Football |
MATCHES Playing with Matches | HRDSEQ Hard Sequence |
DRCHEF Doctor Chef | 559. Maximum Depth of N-ary Tree |
821. Shortest Distance to a Character | 1441. Build an Array With Stack Operations |
1356. Sort Integers by The Number of 1 Bits | 922. Sort Array By Parity II |
344. Reverse String | 1047. Remove All Adjacent Duplicates In String |
977. Squares of a Sorted Array | 852. Peak Index in a Mountain Array |